package org.vincen.helloworld.javassist;

import java.util.Map;
import java.util.SortedMap;

//增删改查，模拟操作的类
public class CRUDSimulation {
	
}

class InfoManager{
	//用户集
	private SortedMap<Integer, String> users;
	
	// 模拟查询操作
    public void query() {
        System.out.println("query");
        for(Map.Entry<Integer, String> entry : users.entrySet()){
        	System.out.println("user : " + entry.getKey() + "::" + entry.getValue());
        }
    }
    // 模拟创建操作
    public void create(String... user) {
        System.out.println("create");
        Integer lastKay = users.lastKey();
        if(users.isEmpty()){
        	users.put(0, user[0]);
        }else {
        	for (int i = 1; i <= user.length; ++i){
        		users.put((lastKay + i), user[i - 1]);
        	}
        }
    }
    // 模拟更新操作
    public void update(Integer userId, String user) {
        System.out.println("update");
        if(users.containsKey(userId)){
        	String s = users.put(userId, user);
        	System.out.println("更新返回值" + s);
        }else {
        	System.out.println("no user");
        }
    }
    // 模拟删除操作
    public void delete(Integer userId) {
        System.out.println("delete");
        if(users.containsKey(userId)){
        	users.remove(userId);
        }else {
        	System.out.println("no user");
        }
    }
}

class Client{
	//未加权限限制的操作
	public void promissionLessManager(){
		InfoManager im = new InfoManager();
		im.create("vincen1", "vincen2", "vincen3", "vincen4", "vincen5");
		im.update(2, "gao");
		im.delete(4);
		im.query();
		System.out.println("操作结束");
	}
}